package com.hongxun.design.ui.myslider;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.facebook.drawee.view.SimpleDraweeView;

import java.io.File;
import java.util.List;

import com.hongxun.design.R;
import com.hongxun.design.ui.statisticsmap.pieview.PieItemBean;
import com.hongxun.design.utils.imageutil.UriUtil;

/**
 * Created by zerdoor_pc on 2015/12/16.
 */
public abstract class MyBaseSliderView extends BaseSliderView {
    protected Context mContext;
    private Bundle mBundle;
    private int mErrorPlaceHolderRes;
    private int mEmptyPlaceHolderRes;
    private String mUrl;
    private String OutUrl;
    private File mFile;
    private int mRes;
    protected MyBaseSliderView.OnSliderClickListener mOnSliderClickListener;
    private boolean mErrorDisappear;
    private List<PieItemBean> items;
    private String mDescription;
    private Boolean TYPE;
    private Boolean hasTitle = true;
    private BaseSliderView.ScaleType mScaleType;


    protected MyBaseSliderView(Context context) {
        super(context);
        this.mScaleType = BaseSliderView.ScaleType.Fit;
        this.mContext = context;
    }

    public MyBaseSliderView empty(int resId) {
        this.mEmptyPlaceHolderRes = resId;
        return this;
    }

    public MyBaseSliderView errorDisappear(boolean disappear) {
        this.mErrorDisappear = disappear;
        return this;
    }

    public MyBaseSliderView error(int resId) {
        this.mErrorPlaceHolderRes = resId;
        return this;
    }

    public MyBaseSliderView description(String description) {
        this.mDescription = description;
        return this;
    }

    public MyBaseSliderView PieData(List<PieItemBean> items) {
        this.items = items;
        return this;
    }

    public MyBaseSliderView setisGG(Boolean TYPE) {
        this.TYPE = TYPE;
        return this;
    }

    public MyBaseSliderView image(String url) {
        if (this.mFile == null && this.mRes == 0) {
            this.mUrl = url;
            return this;
        } else {
            throw new IllegalStateException("Call multi image function,you only have permission to call it once");
        }
    }

    public MyBaseSliderView outUrl(String OutUrl) {

        this.OutUrl = OutUrl;
        return this;
    }

    public MyBaseSliderView image(File file) {
        if (this.mUrl == null && this.mRes == 0) {
            this.mFile = file;
            return this;
        } else {
            throw new IllegalStateException("Call multi image function,you only have permission to call it once");
        }
    }

    public MyBaseSliderView image(int res) {
        if (this.mUrl == null && this.mFile == null) {
            this.mRes = res;
            return this;
        } else {
            throw new IllegalStateException("Call multi image function,you only have permission to call it once");
        }
    }

    public MyBaseSliderView bundle(Bundle bundle) {
        this.mBundle = bundle;
        return this;
    }

    public String getUrl() {
        return this.mUrl;
    }

    public String getOutUrl() {
        return OutUrl;
    }

    public boolean isErrorDisappear() {
        return this.mErrorDisappear;
    }

    public int getEmpty() {
        return this.mEmptyPlaceHolderRes;
    }

    public int getError() {
        return this.mErrorPlaceHolderRes;
    }

    public String getDescription() {
        return this.mDescription;
    }

    public List<PieItemBean> getPieData() {
        return this.items;
    }

    public Boolean isGG() {
        return this.TYPE;
    }

    public Context getActivity() {
        return this.mContext;
    }

    public MyBaseSliderView setOnSliderClickListener(MyBaseSliderView.OnSliderClickListener l) {
        this.mOnSliderClickListener = l;
        return this;
    }

    public MyBaseSliderView setHasTitle(boolean f) {
        hasTitle = f;
        return this;
    }

    protected void bindEventAndShow(final View v, SimpleDraweeView targetImageView) {
        v.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (MyBaseSliderView.this.mOnSliderClickListener != null) {
                    MyBaseSliderView.this.mOnSliderClickListener.onSliderClick(MyBaseSliderView.this);
                }

            }
        });
        /**显示标题栏目**/
        LinearLayout title = (LinearLayout) v.findViewById(R.id.description_layout);
        if (hasTitle) {
            title.setVisibility(View.VISIBLE);
        } else {
            title.setVisibility(View.GONE);
        }

        if (targetImageView != null) {
            if (this.mUrl != null) {
                try {
                    targetImageView.setImageURI(UriUtil.getUri(this.mUrl));
                } catch (Exception e) {
                }

            }
        }
    }

    public MyBaseSliderView setScaleType(BaseSliderView.ScaleType type) {
        this.mScaleType = type;
        return this;
    }

    public BaseSliderView.ScaleType getScaleType() {
        return this.mScaleType;
    }

    public abstract View getView();

    public Bundle getBundle() {
        return this.mBundle;
    }


    public interface OnSliderClickListener {
        void onSliderClick(MyBaseSliderView var1);
    }


}
